#include <QByteArray>
#include <QFile>
#include <QObject>
#include <QString>
#include <QWebChannel>
#include <QWebEngineView>

class FileLoader : public QObject
{
    Q_OBJECT
    Q_PROPERTY(QString m_fileContent READ fileContent NOTIFY fileContentLoaded)

public:
    explicit FileLoader(QObject *parent = nullptr)
        : QObject(parent)
    {}

    QString fileContent() const { return m_fileContent; }

public slots:
    void loadFile(const QString &filePath)
    {
        // 加载文件内容
        QFile file(filePath);
        if (file.open(QIODevice::ReadOnly)) {
            QByteArray fileContent = file.readAll();
            m_fileContent = fileContent.toBase64();
            // 触发信号
            emit fileContentLoaded(m_fileContent);
        }
    }

signals:
    void fileContentLoaded(const QString &fileContent);

private:
    QString m_fileContent;
};
